package dome3;

/**
 * 多接口：
 * 一个类只能有一个父类，但是可以有多个接口
 *
 */
abstract class Animal {
    public String name;

    public Animal(String name) {
        this.name = name;
    }

    abstract public void eat();
}

interface IRunning {
    void run();
}
interface IFly {
    void fly();
}
interface ISwimming {
    void swim();
}


class Dog extends Animal implements IRunning{

    public Dog(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println(name + " 正在吃狗粮！");
    }

    @Override
    public void run() {
        System.out.println(name + "正在跑！");
    }
}

class Fash extends Animal implements ISwimming{

    public Fash(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println(name + " 正在吃鱼粮！");
    }

    @Override
    public void swim() {
        System.out.println(name + "正在游！");
    }
}

class Brid extends Animal implements IFly {

    public Brid(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println(name + " 正在吃鸟粮！");
    }

    @Override
    public void fly() {
        System.out.println(name + "正在飞！");
    }
}

class Duck extends Animal implements IRunning,IFly,ISwimming{

    public Duck(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println(name + " 正在吃鸭粮！");
    }

    @Override
    public void run() {
        System.out.println(name + "鸭子正在跑！");
    }

    @Override
    public void fly() {
        System.out.println(name + "鸭子正在飞！");

    }

    @Override
    public void swim() {
        System.out.println(name + "鸭子正在游！");

    }
}


public class Test {
    public static void allRun(IRunning iRunning) {     //只要把对象的引用传给allRun方法就可以调用实现IRunning这个接口的对象
        iRunning.run();
    }

    public static void allFly (IFly iFly) {     //只要把对象的引用传给allFly方法就可以调用实现IFly这个接口的对象
        iFly.fly();
    }

    public static void allSwim(ISwimming iSwimming) {   //只要把对象的引用传给allSwim方法就可以调用实现ISwimming这个接口的对象
        iSwimming.swim();
    }

    public static void func(Animal animal) {   //只要把子类对象的引用传给func方法就可以调用当前子类对象中的方法
        animal.eat();
    }

    public static void main(String[] args) {
        allRun(new Dog("狗 "));
        allRun(new Duck("鸭子 "));
        func(new Duck("唐老鸭2号"));

        System.out.println("======");

        Brid brid = new Brid("小鸟 ");
        Duck duck = new Duck("鸭子 ");
        allFly(brid);
        allFly(duck);
        func(duck);

        System.out.println("=======");

        allSwim(new Fash("七秒 "));
        allSwim(new Duck("鸭子 "));

        System.out.println("========");

        Duck duck1 = new Duck("唐老鸭 ");
        allRun(duck1);
        allFly(duck1);
        allSwim(duck1);

        System.out.println("========");

        func(new Duck("唐老鸭2号"));

    }
}
